package blog.juejin.socket.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 验证 file 的 inputStream.read()不会阻塞
 * 
 * author : yeswater
 * date : 2024/8/8
 */

public class ReadFileText {
    public static void main(String[] args) {
        /* 这里要用绝对路径 相对路径会读取失败 */
        File file = new File("/Users/wateryes/Desktop/workspace/blog/blog01-socket/src/main/java/blog/juejin/socket/server/test.txt");
        try {
            // 
            InputStream inputStream = new FileInputStream(file);
            byte[] buffer = new byte[4];
            int length = 0;
            while ((length = inputStream.read(buffer)) != -1) {
                System.out.println("length : " + length);
                System.out.println("content : " + new String(buffer, 0, length));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
